import 'package:cloud_medicine/components/cartItem.dart';
import 'package:cloud_medicine/http/shop_api.dart';
import 'package:cloud_medicine/http/config.dart';
import 'package:cloud_medicine/main.dart';
import 'package:cloud_medicine/model/chat_list.dart';
import 'package:flutter/material.dart';

class ChatWithShop extends StatefulWidget {
  final num id;
  final String picture;
  final String shopname;
  ChatWithShop({Key key, this.id, this.picture, this.shopname})
      : super(key: key);

  @override
  _ChatWithShopState createState() => _ChatWithShopState();
}

class _ChatWithShopState extends State<ChatWithShop> {
  Future addChat() async {
    await addChat_api('$backIP/chat/new', {
      'ShopID': widget.id,
      'picture': widget.picture,
      'shopname': widget.shopname
    });
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        addChat();
        Navigator.of(context).push(MaterialPageRoute(
            builder: (BuildContext context) => MyHomePage(
                  initIndex: 2,
                )));
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Icon(
            Icons.chat,
            color: Colors.white,
          ),
          CartListText(
            text: '联系商家',
          )
        ],
      ),
    );
  }
}
